<% content_for(:toolbar) do %>
  <div class="toolbar_buttons">
    <% if can? :create, Alchemy::Picture %>
      <%= render 'alchemy/admin/uploader/button',
        model_class: Alchemy::Picture,
        file_attribute: 'image_file',
        redirect_url: alchemy.admin_pictures_path(
          size: params[:size],
          filter: 'last_upload'
        ) %>
      <div class="toolbar_spacer"></div>
    <% end %>
    <div class="button_group">
      <div class="button_with_label">
        <%= link_to(
          render_icon('zoom-out'),
          alchemy.admin_pictures_path(size: "small", q: params[:q]),
          title: Alchemy.t(:small_thumbnails),
          class: "icon_button please_wait"
        ) %>
      </div>
      <div class="button_with_label">
        <%= link_to(
          render_icon('zoom-equal'),
          alchemy.admin_pictures_path(size: "medium", q: params[:q]),
          title: Alchemy.t(:medium_thumbnails),
          class: "icon_button please_wait"
        ) %>
      </div>
      <div class="button_with_label">
        <%= link_to(
          render_icon('zoom-in'),
          alchemy.admin_pictures_path(size: "large", q: params[:q]),
          title: Alchemy.t(:big_thumbnails),
          class: "icon_button please_wait"
        ) %>
      </div>
      <label><%= Alchemy.t('Image size') %></label>
      <%= hidden_field_tag('size', @size, id: 'overlay_thumbnails_size') %>
    </div>
    <% if can?(:flush, Alchemy::Picture) %>
      <div class="toolbar_spacer"></div>
      <%= toolbar_button(
        icon: 'flush',
        url: alchemy.flush_admin_pictures_path,
        dialog: false,
        link_options: {
          remote: true,
          method: :post
        },
        label: Alchemy.t('Flush picture cache'),
        class: 'icon_button please_wait',
        title: Alchemy.t('Flush picture cache'),
        skip_permission_check: true
      ) %>
    <% end %>
    <div class="toolbar_spacer"></div>
    <div class="button_with_label">
      <%= link_to(
        render_icon('select_all'),
        '',
        id: 'select_all_pictures',
        class: 'icon_button',
        'data-alchemy-hotkey' => 'alt+a'
      ) %>
      <label><%= Alchemy.t("Select all") %></label>
    </div>
  </div>

  <%= render 'alchemy/admin/partials/search_form',
    additional_params: [:filter, :tagged_with, :size] %>
<% end %>

<div id="picture_archive">
  <h1>
    <%= @pictures.total_count %>
    <%= Alchemy::Picture.model_name.human(count: @pictures.total_count) %>
    <%= Alchemy.t("picture_library.filter.#{params[:filter]}") if params[:filter].present? %>
  </h1>
  <%= render 'archive' %>
</div>

<% content_for :javascripts do %>
  <script type="text/javascript" charset="utf-8">
    $(function() {
      Alchemy.pictureSelector();
      $('#select_all_pictures').on('click', function(e) {
        $('.picture_tool.select :checkbox').prop('checked', true).change();
        e.preventDefault;
        return false;
      });
      $('.thumbnail_background').click(function(event) {
        var url = $(this).attr('href');
        var overlay = new Alchemy.ImageOverlay(url);
        overlay.open();
        event.preventDefault();
        return false;
      });
    });
  </script>
<% end %>
